package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.Job;
import com.dyb.recuitment.entity.Setting;
import com.dyb.recuitment.mapper.SettingMapper;
import com.dyb.recuitment.service.ISettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 隐私设置表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-18
 */
@Service
public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> implements ISettingService {

    @Autowired
    private SettingMapper settingMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public int add(Setting setting) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        setting.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return settingMapper.insert(setting);
    }

    @Override
    public int update(Setting setting) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        setting.setUpdateTime(localDateTime);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", setting.getUserId());
        return settingMapper.update(setting, queryWrapper);
    }

    @Override
    public List<Setting> selectBySetting(Setting setting) {
        setting.setStatus(1);
        QueryWrapper<Setting> queryWrapper = new QueryWrapper<>(setting);
        return settingMapper.selectList(queryWrapper);
    }
}
